<template>
		<Dialog :show="show" v-if="show" class="custom-dialog">
			<view class="sucess">
				<view class="name">{{ info.title }}</view>
				<view class="day">您的好友<view class="friend">{{ info.friend }}</view> {{ info?.typeDescription }}</view>
				<view class="first" v-if="info.isFirst">首次分享获得价值</view>
				<view class="worth">{{ info.worth }}</view>
				<view class="btn" @click="jump">{{info.okTxt}}</view>
				<view class="close" @click="submit">关闭</view>
			</view>
		</Dialog>
</template>

<script setup lang="ts">
	import Dialog from "./dialog.vue"
	interface Props{
		show: boolean,
		info: {
			title: string
			friend: string
			typeDescription: string
			worth: string,
			okTxt: string
			href: string | null
			isFirst: boolean
			cb: () => void
		}
	}
	
	// 接收父组件传递的对象
	const props = defineProps<Props>();
	const {show, info }  = props
	const emit = defineEmits(["onOk", "onClose"])
	
	
	const isCurrentPage = (route = '') => {
		const pathArr = route.split("/")
		const pagePath = pathArr[pathArr.length - 2]
		const pages = getCurrentPages();
		const currentPage = pages[pages.length - 1];
		console.log('currentPage',currentPage.route)
		return currentPage.route.includes(pagePath)
	}
	
	
	const jump = () => {
		console.log('跳转', isCurrentPage(info.href), info.href, info);
		info?.cb()
		emit("onOk")
		if(!isCurrentPage(info?.href)){ // 当前弹窗不在 “我的vip奖池页面”, 需要跳转到“我的vip奖池页面”
			uni.navigateTo({
				url:info.href
			})
		}
	}

	const submit = () => {
		info?.cb()
		emit("onClose")
	}
	
</script>

<style scoped lang="scss">
	.sucess{
		width: 100%;
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		padding: 50upx 0;
		background-color: #fff;
		.name{
			font-weight: 600;
			font-size: 36upx;
			color: #081A2A;
			text-align: center;
		}
		.day{
			font-weight: 400;
			font-size: 32upx;
			color: #656565;
			display: flex;
			align-items: center;
			justify-content: center;
			margin-top: 44upx;
			.friend{
				color: #F7AD55;
			}
		}
		.first{
			font-weight: 400;
			font-size: 32upx;
			color: #656565;
			text-align: center;
			display: flex;
			align-items: center;
			justify-content: center;
			margin-top: 10upx;
		}
		.time{
			margin-bottom: 60upx;
			font-weight: 500;
			font-size: 36upx;
			color: #FF6363;
		}
		.worth{
			font-weight: 500;
			font-size: 32upx;
			color: #F7AD55;
			text-align: center;
			font-style: normal;
			text-transform: none;
			margin: 44upx 0;
		}
		.btn{
			width: 550upx;
			height:92upx;
			line-height: 92upx;
			text-align: center;
			background: #2BC888;
			border-radius: 80upx;
			font-weight: 600;
			font-size: 28upx;
			color: #FFFFFF;
		}
		.close{
			margin-top: 32upx;
			font-weight: 400;
			font-size: 28upx;
			color: #999999;
			text-align: center;
			font-style: normal;
			text-transform: none;
		}
	}
</style>

<style>
	.van-popup{
		background-color: rgba(0,0,0,.1) !important;
	}
	

</style>